package com.ruoyi.womp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.womp.domain.WompWeighingApparatus;
import com.ruoyi.womp.service.IWompWeighingApparatusService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 衡器列表Controller
 * 
 * @author mzz
 * @date 2022-12-12
 */
@Controller
@RequestMapping("/womp/weighingApparatus")
public class WompWeighingApparatusController extends BaseController
{
    private String prefix = "womp/weighingApparatus";

    @Autowired
    private IWompWeighingApparatusService wompWeighingApparatusService;

    @RequiresPermissions("womp:weighingApparatus:view")
    @GetMapping()
    public String weighingApparatus()
    {
        return prefix + "/weighingApparatus";
    }

    /**
     * 查询衡器列表列表
     */
    @RequiresPermissions("womp:weighingApparatus:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WompWeighingApparatus wompWeighingApparatus)
    {
        startPage();
        List<WompWeighingApparatus> list = wompWeighingApparatusService.selectWompWeighingApparatusList(wompWeighingApparatus);
        return getDataTable(list);
    }

    /**
     * 导出衡器列表列表
     */
    @RequiresPermissions("womp:weighingApparatus:export")
    @Log(title = "衡器列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WompWeighingApparatus wompWeighingApparatus)
    {
        List<WompWeighingApparatus> list = wompWeighingApparatusService.selectWompWeighingApparatusList(wompWeighingApparatus);
        ExcelUtil<WompWeighingApparatus> util = new ExcelUtil<WompWeighingApparatus>(WompWeighingApparatus.class);
        return util.exportExcel(list, "衡器列表数据");
    }

    /**
     * 新增衡器列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存衡器列表
     */
    @RequiresPermissions("womp:weighingApparatus:add")
    @Log(title = "衡器列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WompWeighingApparatus wompWeighingApparatus)
    {
        return toAjax(wompWeighingApparatusService.insertWompWeighingApparatus(wompWeighingApparatus));
    }

    /**
     * 修改衡器列表
     */
    @RequiresPermissions("womp:weighingApparatus:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WompWeighingApparatus wompWeighingApparatus = wompWeighingApparatusService.selectWompWeighingApparatusById(id);
        mmap.put("wompWeighingApparatus", wompWeighingApparatus);
        return prefix + "/edit";
    }

    /**
     * 修改保存衡器列表
     */
    @RequiresPermissions("womp:weighingApparatus:edit")
    @Log(title = "衡器列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WompWeighingApparatus wompWeighingApparatus)
    {
        return toAjax(wompWeighingApparatusService.updateWompWeighingApparatus(wompWeighingApparatus));
    }

    /**
     * 删除衡器列表
     */
    @RequiresPermissions("womp:weighingApparatus:remove")
    @Log(title = "衡器列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wompWeighingApparatusService.deleteWompWeighingApparatusByIds(ids));
    }
}
